﻿using Llibs.Log;
using UnityEngine;
using YooAsset;

namespace Client.Base
{
    public class Main : MonoBehaviour
    {
        [Header("0:正式服 1:测试服 2:开发服")]
        [Tooltip("0:正式服 1:测试服 2:开发服")]
        [SerializeField] private int env = 0;
        [SerializeField] private int channelID = 1;
        [SerializeField] private bool runInBackground = false;
        [SerializeField] private bool enableLog = true;
        [SerializeField] private EPlayMode playMode;

        private void Awake()
        {
            Application.runInBackground = runInBackground;
            AppInfo.ChannelID = channelID;
            AppInfo.Env = env;

#if UNITY_WEBGL && !UNITY_EDITOR
            playMode = EPlayMode.WebPlayMode;
#endif
            InitLog();
            InitPatch();
        }

        private void InitLog()
        {
            LogConfig cfg = new LogConfig
            {
                enableLog = enableLog,
                enableTrace = true,
                enableCover = false,
                enableThreadID = false,
                enableSave = false,
                enableTime = true,
                logPrefix = "",
                loggerEnum = ELoggerType.Unity,
            };

            LLog.InitSettings(cfg);
        }

        private void InitPatch()
        {
            PatchHandle patch = new PatchHandle();
            patch.Run(playMode);
        }
    }
}

